﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WeekendPool.Models;

namespace WeekendPool.Controllers           // necessary to specify "DBEntity" in the add other in the data context class to Use Entity Framework when creating new controller
{
    public class SaturdayController : Controller
    {
        private DBEntity db = new DBEntity();

        //
        // GET: /Default1/

        public ActionResult Index()
        {
            return View(db.Saturdays.ToList());
        }

        //
        // GET: /Default1/Details/5

        public ActionResult Details(string id = null)
        {
            Saturday saturday = db.Saturdays.Find(id);
            if (saturday == null)
            {
                return HttpNotFound();
            }
            return View(saturday);
        }

        //
        // GET: /Default1/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Default1/Create

        [HttpPost]
        public ActionResult Create(Saturday saturday)
        {
            if (ModelState.IsValid)
            {
                db.Saturdays.Add(saturday);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(saturday);
        }

        //
        // GET: /Default1/Edit/5

        public ActionResult Edit(string id = null)
        {
            Saturday saturday = db.Saturdays.Find(id);
            if (saturday == null)
            {
                return HttpNotFound();
            }
            return View(saturday);
        }

        //
        // POST: /Default1/Edit/5

        [HttpPost]
        public ActionResult Edit(Saturday saturday)
        {
            if (ModelState.IsValid)
            {
                db.Entry(saturday).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(saturday);
        }

        //
        // GET: /Default1/Delete/5

        public ActionResult Delete(string id = null)
        {
            Saturday saturday = db.Saturdays.Find(id);
            if (saturday == null)
            {
                return HttpNotFound();
            }
            return View(saturday);
        }

        //
        // POST: /Default1/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(string id)
        {
            Saturday saturday = db.Saturdays.Find(id);
            db.Saturdays.Remove(saturday);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}